#ifndef _MYTEST_DEFINE_H
#define _MYTEST_DEFINE_H

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <time.h>
#include <stdarg.h>
#include <vector>
#include <stddef.h>
#include <algorithm>
#include <set>
#include <memory>

#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <fstream>
#include <math.h>
#include <unistd.h>
#include <map>
#include <dirent.h>
#include <functional>
#include <pthread.h>
#include <mutex>

#ifdef  UNICODE
typedef wchar_t _tchar;
typedef std::wstring _tstring;
typedef const std::wstring _tcstring;
#else
typedef char _tchar;
typedef std::string _tstring;
typedef const std::string _tcstring;
#endif  // UNICODE

// define system info
#define JOTASYS_JSONARG_NAME        "systemName"
#define JOTASYS_JSONARG_VERSION     "system_version"
#define JOTASYS_JSONARG_DESCRIPTION "description"
#define JOTASYS_JSONARG_DATE        "updateDate"
#define JOTASYS_JSONARG_APPLICATION "appInfos"
#define JOTASYS_JSONARG_SN          "sn"

// define from afm response json item
#define JOTAAPP_JSONARG_DESCRIPTION "description"  // This is a demo application for ivi
#define JOTAAPP_JSONARG_NAME        "name"         // IVI_HMI
#define JOTAAPP_JSONARG_SNAME       "shortname"
#define JOTAAPP_JSONARG_ID          "id"           // ivi_hmi@0.1
#define JOTAAPP_JSONARG_VERSION     "version"      // 0.1
#define JOTAAPP_JSONARG_AUTHOR      "author"       // TOYOA
#define JOTAAPP_JSONARG_EMAIN       "author-email" //
#define JOTAAPP_JSONARG_WIDTH       "width"        //
#define JOTAAPP_JSONARG_HEIGHT      "height"       //
#define JOTAAPP_JSONARG_ICON        "icon"         // xxxx/xxxx/icon.svg
#define JOTAAPP_JSONARG_PORT        "http-port"    // 1054

// define for post web-service json item
#define JOTAAPP_POSTJSON_NAME "app_name"
#define JOTAAPP_POSTJSON_VERSION "app_version"
#define JOTAAPP_POSTJSON_ID "app_id"

// define from web service response json item
#define JOTAAPP_WEBJSON_NAME "name"
#define JOTAAPP_WEBJSON_VERSION "version"
#define JOTAAPP_WEBJSON_URL "url"
#define JOTAAPP_WEBJSON_MD5 "MD5"
#define JOTAAPP_WEBJSON_README "readme"

// define from afm-commond response json item
#define JOTAAPP_CMDJSON_ADD "added"

// url and key
#define JOTA_CURL_HTTP_PORT "http://192.168.143.1:8080/"
#define JOTA_CURL_HTTP_KEY "junma/jota?"
#define JOTA_CURL_DLWD_KEY "junma/"
#define JOTA_CURL_POST_KEY "jotaInfo="

// system info key
#define JOTA_SYSPROP_VERKEY "ro.product.release_version" // release_version
#define JOTA_SYSPROP_SNKEY  "ro.product.sn"
#define JOTA_SYSPROP_URLKEY "ro.jota.url"
#define JOTA_SYSRESP_ERROR  "failed"

// qnx info define
#define JOTA_QNX_DSTFILE_NAME "application.cfg"
#define JOTA_QNX_KEY_NAME "NAME"
#define JOTA_QNX_KEY_VERS "VERSION"

// define error message
#define  JOTA_ERRORMSG_OUT "Wrong inside!"


enum EventType {
   Event_Val_Min = 0,

   Event_Check = Event_Val_Min,
   Event_Update,
   Event_Download,
   Event_End,

   Event_Error,

   Event_Val_Max = Event_Error
};

enum LOG_LEVEL{
    LOG_LEVEL_NONE = 0,
    LOG_LEVEL_ERROR,
    LOG_LEVEL_WARNING,
    LOG_LEVEL_NOTICE,
    LOG_LEVEL_INFO,
    LOG_LEVEL_DEBUG,
    LOG_LEVEL_MAX = LOG_LEVEL_DEBUG
};
struct StSystemInfo
{
    _tstring strVersion;
    _tstring strSN;

    void st_print() const
    {
        printf("=======================================================================================\n");
        printf("**  system info  : dblVersion    = [%s]\n", strVersion.c_str());
        printf("**  system info  : strSN         = [%s]\n", strSN.c_str());
        printf("=======================================================================================\n");
    }
};

struct StAppInfo
{
    StAppInfo()
        : bVerify(false)
        , beUpdated(false)
        , bQnx(false)
        , nPort(0)
    {
    }

    bool  bVerify;
    bool  beUpdated;
    bool  bQnx;
    double  nPort;

    _tstring strName;
    _tstring strVersion;
    _tstring strId;
    _tstring strPath;
    _tstring strUrl;
    _tstring strMD5;
    _tstring strReadme;

    void st_print() const
    {
        printf("=======================================================================================\n");
        printf("**  appinfo  : nPort          = [%.0lf]\n", nPort);
        printf("**  appinfo  : strName        = [%s]\n", strName.c_str());
        printf("**  appinfo  : dblVersion     = [%s]\n", strVersion.c_str());
        printf("**  appinfo  : strId          = [%s]\n", strId.c_str());
        printf("**  appinfo  : strPath        = [%s]\n", strPath.c_str());
        printf("**  appinfo  : strUrl         = [%s]\n", strUrl.c_str());
        printf("**  appinfo  : strMD5         = [%s]\n", strMD5.c_str());
        printf("**  appinfo  : strReadme      = [%s]\n", strReadme.c_str());
        printf("=======================================================================================\n");
    }
};

struct StUpdateInfo
{
    StUpdateInfo() {}

    StSystemInfo stSys;
    std::vector<StAppInfo> vctApps;

    void st_print() const
    {
        stSys.st_print();
        printf("=======================================================================================\n");
        printf("**  update info  : vctApps.size  = [%lu]\n", vctApps.size());
        printf("=======================================================================================\n");
        if (vctApps.size() > 0) {
            for (auto vec : vctApps) {
                vec.st_print();
            }
        }
    }
};


enum eCommondType
{
    ECT_DETAIL,
    ECT_INSTALL,
    ECT_ONCE,
    ECT_PAUSE,
    ECT_RESUME,
    ECT_RUNNABLES,
    ECT_RUNNERS,
    ECT_START,
    ECT_STATE,
    ECT_TERMINATE,
    ECT_UNINSTALL,
    ECT_MAX
};

typedef eCommondType _tECmdType;
typedef const eCommondType _tcECmdType;
#endif // _MYTEST_DEFINE_H
